
//
//  ZJWelcomeViewController.swift
//  Webo
//
//  Created by 曾静 on 16/6/26.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit
import SDWebImage

class ZJWelcomeViewController: UIViewController {

    override func loadView() {
        
        view = bjImageView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    
        setupUI()

    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        mainImageView.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(view).offset(100)
        }
        
      
        UIView.animateWithDuration(0.5, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.lab.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        
                        //将自己销毁掉
                        
//                UIApplication.sharedApplication().keyWindow?.rootViewController = ZJBaseTabbarViewController()
            NSNotificationCenter.defaultCenter().postNotificationName(switchVc, object: "welcome")
                       
                        
                })
        }
    }
    
    func setupUI(){
        
        view.addSubview(mainImageView)
        
        view.addSubview(lab)
        
        
        mainImageView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(view).offset(400)
            
            make.size.equalTo(CGSizeMake(90, 90))
            
            make.centerX.equalTo(view)
    
        }
        
        lab.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(mainImageView.snp_bottom).offset(16)
            
            make.centerX.equalTo(view)
        }
        
    }

    
     private lazy var bjImageView:UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    
    
    private lazy var mainImageView:UIImageView = {
        
        let main = UIImageView()
        
        main.layer.cornerRadius = 45
        
        main.layer.borderColor = ThemeColor.CGColor
        
        main.layer.borderWidth = 3
        
        main.sd_setImageWithURL(NSURL(string: ZJUserInfoTools.shareUserInfo.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        
        main.layer.masksToBounds = true
        
        return main
        
    }()
    
    private lazy var lab:UILabel = {
        
        
        let lab = UILabel()
        
        lab.textAlignment = .Center
        
        lab.text = (ZJUserInfoTools.shareUserInfo.userAccount?.screen_name)! + "欢迎回来"
        
        lab.font = UIFont.systemFontOfSize(17)
        
        lab.textColor = UIColor.grayColor()
        
        lab.alpha = 0
        
        return lab
        
    }()
    
    
}
